<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_select">
        <div class="input">
          <el-input v-model="dataForm.title" :placeholder="$t('common.please_input') + $t('business.information.title')" clearable>
          </el-input>
        </div>
        <div class="input">
          <el-select v-model="dataForm.status" :placeholder="$t('common.please_select') + $t('common.status')" clearable>
            <el-option :label="$t('common.all')" value=""></el-option>
            <el-option :label="$t('common.enable')" value="1"></el-option>
            <el-option :label="$t('common.disable')" value="2"></el-option>
          </el-select>
        </div>
        <div class="date">
          <el-date-picker v-model="dataForm.publish_time" type="daterange" :range-separator="$t('common.to')" :start-placeholder="$t('common.start_time')" :end-placeholder="$t('common.end_time')" clearable>
          </el-date-picker>
        </div>
        <div class="input">
          <el-button icon="Search" @click="getDataList(true)">
            {{ i18n('common.search') }}
          </el-button>
        </div>
      </div>

      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" stripe>
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" label="#" width="100">
          </el-table-column>

          <el-table-column :label="$t('business.information.category_id')" width="80">
            <template v-slot="scope">
              <span v-if="scope.row.category">{{ scope.row.category.chinese_title }}</span>
            </template>
          </el-table-column>

          <el-table-column :label="$t('business.information.machine_id')" width="100">
            <template v-slot="scope">
              <span v-if="scope.row.machine">{{ scope.row.machine.chinese_title }}</span>
            </template>
          </el-table-column>

          <el-table-column :label="i18n('business.information.shipowner_id')" width="200">
            <template v-slot="scope">
              <span v-if="scope.row.shipowner">{{ scope.row.shipowner.chinese_name }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="title" :label="i18n('business.information.title')" min-width="100">
          </el-table-column>

          <el-table-column prop="publish_time" :label="i18n('business.information.publish_time')" width="100">
          </el-table-column>

          <el-table-column :label="$t('common.sort')" width="200">
            <template v-slot="scope">
              <el-input-number
                v-model="scope.row.sort"
                :min="0"
                :max="999"
                @change="handleSort($event, scope.row.id)"/>
            </template>
          </el-table-column>

          <el-table-column :label="$t('common.is_recommend')" width="80">
            <template v-slot="scope">
              <el-switch
                v-model="scope.row.is_recommend"
                :active-value="1"
                :inactive-value="2"
                size="large"
                inline-prompt
                :active-text="$t('common.recommended')"
                :inactive-text="$t('common.unrecommended')"
                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
                @change="handleStatus($event, scope.row.id, 'is_recommend')">
              </el-switch>
            </template>
          </el-table-column>

          <el-table-column prop="create_time" :label="i18n('business.information.create_time')" width="160">
          </el-table-column>
        </el-table>

        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="business-information-recommend-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"
  import { datetime } from "@/utils/filter"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('business/information/recommend')

  const dataForm = reactive([
    'title',
    'status',
    'publish_time',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    handleSort,
    handleStatus,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    deleteHandle,
  } = useTable(model.value, dataForm)


  onMounted(() => {
    getDataList(model)
  })
</script>
